package com.ywl.optional;

import com.ywl.entity.Author;

import java.util.Optional;

/**
 * optional 用于过滤 filter
 *
 * @author 24040
 * @name OptionalDemo01
 * @date 2022-08-23 16:51
 */
public class OptionalDemo03 {
    public static void main(String[] args) {
        Optional<Author> optionalAuthor = getOptionalAuthor();
        optionalAuthor.filter(author -> author.getAge() > 30)
                .ifPresent(author -> System.out.println(author.getAge()));
    }

    public static Optional<Author> getOptionalAuthor() {
        Author author = new Author
                (1L, "蒙多", 18, "一个从菜刀中明悟哲理的祖安人", null);
        return Optional.ofNullable(author);
    }
}
